package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.PageSort;
import com.aaa.entity.Question;
import com.aaa.service.QuestionFPAService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author ：Lim
 * @date ：Created in 2022/6/28 9:12
 * @description：
 * @modified By：
 * @version:
 */
@Controller
@RequestMapping("ques")
public class QuestionFPAController extends BaseController {

    MyReturn myReturn = new MyReturn();

    @Autowired
    private QuestionFPAService questionService;
    @RequestMapping("quest.do")
    private String Pages() {
        return "showQuestion";
    }
    @RequestMapping("selectques.do")
    @ResponseBody
    public MyReturn selectQuestion(PageSort pageSort, Question question) {
        Page allDept = questionService.selectQuestion(pageSort, question);
        myReturn.setCount(allDept.getTotal());
        myReturn.setData(allDept.getResult());
        return super.getSuccessResult(myReturn);

    }

    @RequestMapping("insertques.do")
    @ResponseBody
    public MyReturn insertQuestion(Question question) {
        boolean b = questionService.insertQuestion(question);
        if (b) {
            return super.getSuccessResult(myReturn);
        }
        return super.getFailResult(myReturn);
    }

    @RequestMapping("deleteques.do")
    @ResponseBody
    public MyReturn deleteQuestionByid(Integer id) {
        boolean b = questionService.deleteQuestion(id);
        if (b) {
            return super.getSuccessResult(myReturn);
        }
        return super.getFailResult(myReturn);
    }

    @RequestMapping("updateques.do")
    @ResponseBody
    public MyReturn updateques(Question question) {
        boolean b = questionService.updateQuestion(question);
        if (b) {
            return super.getSuccessResult(myReturn);
        }
        return super.getFailResult(myReturn);
    }

    @RequestMapping("deleteByAllId.do")
    @ResponseBody
    public MyReturn deleteByAllId(String[] id) {
        boolean b = questionService.deleteQuestionByAllId(id);
        if (b) {
            return super.getSuccessResult(myReturn);
        }
        return super.getFailResult(myReturn);
    }
    @RequestMapping("selectAllques.do")
    @ResponseBody
    public void selectAllques(Question question, HttpSession session) {
        List<Question> questions = questionService.answer(question);
        System.out.println(questions.toString()+"---------------------------SAS--------------------------------------");
        session.setAttribute("question",questions);
    }
}